package com.xc.dao;

import com.xc.pojo.SysUser;
import com.xc.vo.UserVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysUserMapper {

    /**
     * 根据用户名查询用户
     * @param userName
     * @return
     */
    SysUser queryUserByUserName(String userName);

    /**
     * 通过部门id获取用户
     * @param deptId
     * @return
     */
    @Select("select count(1) from sys_user where deptId=#{deptId}")
    int getUserByDeptId(Integer deptId);

    /**
     * 根据角色编号查询该角色下的用户的数量
     * @param roleId
     * @return
     */
    @Select("select count(1) from sys_user_role t1 inner join sys_user t2 on t2.id=t1.uid where t1.rid=#{roleId};")
    int getUserByRoleId(Integer roleId);

    /**
     * 查询用户列表
     * @param userVo
     * @return
     */
    List<SysUser> queryUserList(UserVo userVo);

    /**
     * 添加用户
     * @param sysUser
     * @return
     */
    int addUser(SysUser sysUser);

    /**
     * 修改用户
     * @param sysUser
     * @return
     */
    int updateUser(SysUser sysUser);

    /**
     * 删除用户角色关系表数据
     * @param id
     */
    @Delete("delete from sys_user_role where uid = #{id}")
    void deleteUserRoleByUserId(Integer id);

    /**
     * 根据id删除
     * @param id
     * @return
     */
    int deleteUser(Integer id);
    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    @Select("select * from sys_user where userName = #{userName}")
    SysUser getUserByUserName(String userName);
}
